<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#timeDiv
			{
					background-color: #000000;
					color: white;
					font-size: 80px;
			}
			
		</style>
	</head>
	<body>
		<button onclick="test1()">开启</button>
		<button onclick="test2()">暂停</button>
		<div id="timeDiv">13:55:00</div>

		<script type="text/javascript">
			function refreshTime() {
				var now = new Date();
				var h = "" + now.getHours();
				if (h.length < 2) h = "0" + h;
				var m = "" + now.getMinutes();
				if (m.length < 2) m = "0" + m;
				var s = "" + now.getSeconds();
				if (s.length < 2) s = "0" + s;
				timeDiv.textContent = h + ":" + m + ":" + s;
			}
			refreshTime();

			function test1() {
				t = setInterval(refreshTime, 1000);
			}

			function test2() {
				// 关闭定时器
				clearInterval(t);
			}
		</script>
	</body>
</html>
